const app = getApp()
const WXAPI = require("../../../api/newApi")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isChoice: false,
    holdId:'',
    info:{},
    unitPrice: '',//单价
    description:'',//说明
    isShow: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      statusHeight: app.gettop.height,
      status: app.gettop.status,
      navHeight:app.gettop.navHeight,
      mobbleBottom: app.mobile.mobbleBottom
    })
    this.data.holdId = options.id
    this.getEcho()
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  back(){
    wx.navigateBack({
      delta: 0,
    })
  },
  choice(){
    this.data.isChoice = !this.data.isChoice
    this.setData({
      isChoice: this.data.isChoice
    })
  },
  getEcho(){ //获取转卖回显
    var data = {
      holdId: this.data.holdId,
      assetType: 2 //2券 3卡
    }
    WXAPI.echo(data,(res)=>{
      this.setData({
        info: res.result
      })
    })
  },
  bindinput(e){ //监听输入
    console.log(e.detail.value)
    this.data.unitPrice = e.detail.value
    if(this.data.unitPrice!=''){
      this.setData({
        isShow: true
      })
    }else{
      this.setData({
        isShow:false
      })
    }
  },
  bindtext(e){
    this.data.description = e.detail.value
  },
  sumit(){ //resell 转卖提交
    var data = {
      resellCount: 1, //转卖数量
      resellType: 2, //转卖类型 1卡 2券 
      unitPrice: this.data.unitPrice, //单价
      description: this.data.description, //说明
      holdId: this.data.holdId,
    }
    WXAPI.resell(data,(res)=>{
      this.setData({
        isShow: false
      })
      if (res.code == 200) {
        let info = JSON.stringify(res.result)
        wx.showToast({
          title: '转卖成功',
        })
        setTimeout(()=>{
          wx.navigateTo({
            url: '/userPageB/pages/resellVouch/resellVouch_success/resellVouch_success?info=' + info
          })
        },800)
      }else{
        this.setData({
          isShow: true
        })
      }
    })
    
  },
})